 #include <pcl/io/openni_grabber.h>
 #include <pcl/visualization/cloud_viewer.h>
 #include <iostream>
 #include <pcl/io/pcd_io.h>
 #include <pcl/point_types.h>
 #include <pcl/features/vfh.h>

 class SimpleOpenNIViewer
 {
   public:
	   SimpleOpenNIViewer (std::string fileName) : viewer ("PCL OpenNI Viewer"), fileName (fileName) {}

     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloudx)
     {
       pcl::io::savePCDFileBinary (fileName, *cloudx);
     }

     void run ()
     {
       pcl::Grabber* interface = new pcl::OpenNIGrabber();

       boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

       interface->registerCallback (f);
       interface->start ();
	   boost::this_thread::sleep(boost::posix_time::seconds(1.2));
       interface->stop ();
     }

     pcl::visualization::CloudViewer viewer;
	 std::string fileName;
 };

 int captureScreen (std::string filePath)
 {
   SimpleOpenNIViewer v(filePath);
   v.run ();
   //boost::this_thread::sleep(boost::posix_time::seconds(2));
   return 0;
 }


 int main ( int argc, char** argv ){

	 if(argc != 2){
		 std::cerr << "ERROR: Syntax is " << argv[0] << " <filename>.pcd" << std::endl;
		 std::cerr << "EXAMPLE: ./" << argv[0] << " scene.pcd" << std::endl;
		 
		 return -1;
	 }

	 remove(argv[1]);

	 captureScreen(argv[1]);
	 return 0;
 }

